/*
    Last change:  RM   17 Jan 2001    11:35 
*/

//*****************************************************************************
//
//      COPYRIGHT (c) ATMEL Norway, 1996-2001
//
//      The copyright to the document(s) herein is the property of
//      ATMEL Norway, Norway.
//
//      The document(s) may be used  and/or copied only with the written
//      permission from ATMEL Norway or in accordance with the terms and
//      conditions stipulated in the agreement/contract under which the
//      document(s) have been supplied.
//
//*****************************************************************************
//
//  File........: DATAFLASH.H
//
//  Author(s)...: ATMEL Norway
//
//  Target(s)...: Independent
//
//  Description.: Defines and prototypes for AT45Dxxx
//
//  Revisions...:
//
//  YYYYMMDD - VER. - COMMENT                                       - SIGN.
//
//  20010117 - 0.10 - Generated file                                -  RM
//
//*****************************************************************************

#ifndef __DATAFLASH_INCLUDED
#define __DATAFLASH_INCLUDED
#endif


//General macro definitions
#define sbi(port,bit)   (port |=  (1<<bit))  //Set 1 the bit in the port
#define cbi(port,bit)   (port &= ~(1<<bit))  //Clear 0 the bit in the port

#define SetBit(x,y)      (x |= (y))          //Set 1 all bits in y
#define ClrBit(x,y)      (x &=~(y))          //Clear 0 all bits in y
#define ChkBit(x,y)      (x  & (y))          //Check or compare bits x AND y


//Dataflash opcodes
#define FlashPageRead               0x52   // Main memory page read
#define FlashToBuf1Transfer         0x53   // Main memory page to buffer 1 transfer
#define Buf1Read                    0x54   // Buffer 1 read
#define FlashToBuf2Transfer         0x55   // Main memory page to buffer 2 transfer
#define Buf2Read                    0x56   // Buffer 2 read
#define StatusReg                   0x57   // Status register
#define AutoPageReWrBuf1            0x58   // Auto page rewrite through buffer 1
#define AutoPageReWrBuf2            0x59   // Auto page rewrite through buffer 2
#define FlashToBuf1Compare          0x60   // Main memory page to buffer 1 compare
#define FlashToBuf2Compare          0x61   // Main memory page to buffer 2 compare
#define ContArrayRead               0x68   // Continuous Array Read (Note : Only A/B-parts supported)
#define FlashProgBuf1               0x82   // Main memory page program through buffer 1
#define Buf1ToFlashWE               0x83   // Buffer 1 to main memory page program with built-in erase
#define Buf1Write                   0x84   // Buffer 1 write
#define FlashProgBuf2               0x85   // Main memory page program through buffer 2
#define Buf2ToFlashWE               0x86   // Buffer 2 to main memory page program with built-in erase
#define Buf2Write                   0x87   // Buffer 2 write
#define Buf1ToFlash                 0x88   // Buffer 1 to main memory page program without built-in erase
#define Buf2ToFlash                 0x89   // Buffer 2 to main memory page program without built-in erase
#define PageErase					0x89   // Erase



//Pin definitions for interface to the Dataflash


//Dataflash macro definitions
#define DF_CS_active       cbi(PORTB,0)   //Clear 0 the bit 0 of PORTB (CS)
#define DF_CS_inactive     sbi(PORTB,0)   //Set 1 the bit 0 of PORTB (CS)


//Function definitions
void DF_SPI_init (void);
unsigned char DF_SPI_RW (unsigned char output);
unsigned char Read_DF_status (void);
void Page_To_Buffer (unsigned int PageAdr, unsigned char BufferNo);
void Buffer_Read_Str (unsigned char BufferNo, unsigned int IntPageAdr, unsigned int No_of_bytes, unsigned char *BufferPtr);
void Buffer_Write_Str (unsigned char BufferNo, unsigned int IntPageAdr, unsigned int No_of_bytes, unsigned char *BufferPtr);
void Buffer_To_Page (unsigned char BufferNo, unsigned int PageAdr);




void Write_Flash_Memory (unsigned int No_bytes, unsigned char *BufferPtr);
void Read_Flash_Memory (unsigned int No_of_bytes, unsigned char *BufferPtr);
void Erase_Page ();

// *****************************[ End Of DATAFLASH.H ]*****************************

